package com.anlu.yue.model;


import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

/**
 * 类描述:状态码
 *
 * @author 赵希坤 zhaoxikun
 * @date 2020/12/10 19:11
 */
public class ResultCode implements SuperCodeMsg {
    /**
     * code码
     */
    private final Integer code;
    /**
     * 描述
     */
    private String msg;

    private ResultCode(Integer code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    /**
     * new
     *
     * @param code code码
     * @param msg  描述
     * @return ResultCode
     */
    public static ResultCode newInstance(Integer code, String msg) {
        return new ResultCode(code, msg);
    }

    @Override
    public Integer getCode() {
        return code;
    }

    @Override
    public String getMsg() {
        return msg;
    }


    /**
     * 是否为成功的返回码
     *
     * @return boolean
     */
    public boolean isSuccess() {
        return this.is(SuperResultCodeUtil.SUCCESS.code);
    }

    @Override
    public String toString() {
        return "ResultCode{" +
                "code=" + code +
                ", msg='" + msg + '\'' +
                '}';
    }
}
